//
//  WLHomeActivityOpearCell.swift
//  WalkerLove
//
//  Created by Z on 2020/4/18.
//  Copyright © 2020 Carlson. All rights reserved.
//  活动运营

import UIKit

let kHomeActivityOpearKey = "kHomeActivityOpearIdentifyKey"

class WLHomeActivityOpearCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {

    var collection: UICollectionView?
    var urls: [String] = [String]()
    
    var datas: [String] {
        set(m){
            self.urls = m
            collection?.reloadData()
        }
        get{
            return [String]()
        }
    }
        
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initSubviews()
    }

    func initSubviews() {
        let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 10
        layout.sectionInset = UIEdgeInsets(top: 10, left: 15, bottom: 0, right: 15)
        layout.itemSize = CGSize(width: (kScreen.width-40)/2, height: 100/167.5*(kScreen.width-40)/2)
        layout.scrollDirection = .vertical
        collection = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
        collection?.register(WLHomeActivityOperaCellItem.self, forCellWithReuseIdentifier:kHomeActivityOpearKey)
        collection?.delegate = self
        collection?.dataSource = self
        collection?.backgroundColor = .clear
        contentView.addSubview(collection!)
        
        collection?.snp.makeConstraints({
            $0.edges.equalTo(0)
        })
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return urls.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let item = collectionView.dequeueReusableCell(withReuseIdentifier: kHomeActivityOpearKey, for: indexPath)
        if let m = item as? WLHomeActivityOperaCellItem {
            m.urlStr = urls[indexPath.row]
        }
        return item
    }
}
